$(document).ready(function(){
	
	$('a.openid').click( function(e) {
		e.preventDefault();
		e.stopPropagation();
		$('a.emailpassword, div.openid, input.openid').show();
		$('a.openid, div.emailpassword, input.emailpassword').hide();
		setCookie('epiLogin','openid',90);
	});
	
	$('a.emailpassword').click( function(e) {
		e.preventDefault();
		e.stopPropagation();
		$('a.openid, div.emailpassword, input.emailpassword').show();
		$('a.emailpassword, div.openid, input.openid').hide();
		setCookie('epiLogin','emailpassword',90);
	});
	
	var logindefault = readCookie('epiLogin');

	if ( logindefault == undefined || logindefault == 'emailpassword') $('a.emailpassword').click();
	else if ( logindefault == 'openid') $('a.openid').click();

});

function setCookie(cookieName,cookieValue,nDays) {
	 var today = new Date();
	 var expire = new Date();
	 if (nDays==null || nDays==0) nDays=1;
	 expire.setTime(today.getTime() + 3600000*24*nDays);
	 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString(),';path=/;';
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}